﻿package net.chrisjrock.ui
{
	import flash.utils.Dictionary;
	
	/**
	 * ...
	 * @author Christopher J. Rock
	 */
	public class ConfigControlScheme 
	{
		protected var _affirmative:int = -1;
		protected var _negative:int = -1;
		protected var _activeToggle:int = -1;
		protected var _fullScreenToggle:int = -1;
		
		protected var _controlById:Dictionary;
		protected var _controlByKey:Dictionary;
		
		public function ConfigControlScheme ():void
		{
			_controlById = new Dictionary();
			_controlByKey = new Dictionary();
		}
		
		public function destroyInternal ():void
		{
			_affirmative = _negative = _activeToggle = _fullScreenToggle = 0;
			_controlById = null;
			_controlByKey = null;
		}
		
		public function clone ():ConfigControlScheme
		{
			var cloneScheme:ConfigControlScheme = new ConfigControlScheme();
			cloneScheme.setAffirmative(_affirmative);
			cloneScheme.setNegative(_negative);
			cloneScheme.setActiveToggle(_activeToggle);
			cloneScheme.setFullScreenToggle(_fullScreenToggle);
			return cloneScheme;
		}
		
		public function addControl (control:KeyboardControl):Boolean
		{
			if (_controlById[control.getId()] || _controlByKey[control.getKeyCode()])
			{
				return false;
			}
			
			_controlById[control.getId()] = _controlByKey[control.getKeyCode()] = control;
			
			return true;
		}
		
		public function removeControl (control:KeyboardControl):void
		{
			delete _controlById[control.getId()];
			delete _controlByKey[control.getKeyCode()];
		}
		
		public function hasControl (control:KeyboardControl):Boolean
		{
			return _controlById[control.getId()] == control;
		}
		
		public function getControlById (id:String):KeyboardControl
		{
			return _controlById[id];
		}
		
		public function getControlByKey (keyCode:int):KeyboardControl
		{
			return _controlByKey[keyCode];
		}
		
		public function getAffirmative ():int
		{
			return _affirmative;
		}
		
		public function setAffirmative (value:int):void
		{
			_affirmative = value;
		}
		
		public function getNegative ():int
		{
			return _negative;
		}
		
		public function setNegative (value:int):void
		{
			_negative = value;
		}
		
		public function getActiveToggle ():int
		{
			return _activeToggle;
		}
		
		public function setActiveToggle (value:int):void
		{
			_activeToggle = value;
		}
		
		public function getFullScreenToggle ():int
		{
			return _fullScreenToggle;
		}
		
		public function setFullScreenToggle (value:int):void
		{
			_fullScreenToggle = value;
		}
	}
	
}